<template>
  <div class="shell">
    <input v-model="keyword" placeholder="请输入书籍、作者、分类" type="text" @keyup.enter="search">
    <div>
      <i class="iconfont icon-zhipai" @click="search"></i>
      <i class="iconfont icon-search" @click="search"></i>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router';
import "@/assets/iconfont.css"

const router = useRouter();
const keyword = ref('');
const search = () => {
  if (keyword.value.trim()) {
    router.push({ path: `/search/${keyword.value}` });
  }
}
</script>

<style scoped>
* {
  outline: none;
  padding: 0;
  margin: 0;
  text-decoration: none;
}

.shell {
  position: relative;
  width: 350px;
  height: 20px;
  padding: 12px;
  background-color: #ffffff;
  box-shadow: 0 5px 50px #ff7575, 0 0 0 8px #fff;
  border-radius: 20px;
  display: flex;
  align-items: center;
}

.shell input {
  width: 75%;
  height: 20px;
  color: rgb(83, 74, 74);
  font-size: 16px;
  border: 0;
  background-color: transparent
}

.shell input::placeholder {
  color: rgb(83, 74, 74);
}

.shell div {
  flex: 1;
  color: #fff;
  background-color: transparent;
  display: flex;
  justify-content: flex-end;
  align-items: center;
}

.icon-search {
  align-content: center;
  justify-content: flex-end;
  color: rgb(129, 124, 124);
  font-size: 20px;
  opacity: 1;
  transition: .3s;
  cursor: pointer;
}

.icon-zhipai {
  font-size: 30px;
  opacity: 0;
  transform: translateX(-50px);
  color: rgb(129, 124, 124);
  transition: .3s;
  cursor: pointer;
}

.shell div:hover .icon-search {
  transform: translateX(0);
  opacity: 0;
}

.shell div:hover .icon-zhipai {
  transform: translateX(35px);
  opacity: 1;
}

.shell div::before {
  content: 'GO!';
  position: absolute;
  display: block;
  font-size: 15px;
  background-color: #ff7575;
  padding: 5px 10px;
  right: -70px;
  border-radius: 10px;
  transition: .3s;
  opacity: 0;
  animation: box 1s infinite ease;
}

.shell div:hover::before {
  opacity: 1;
}

@keyframes box {
  0% {
    transform: rotate(0deg);
  }

  33% {
    transform: rotate(8deg);
  }

  66% {
    transform: rotate(-8deg);
  }

  100% {
    transform: rotate(0deg);
  }
}
</style>